package com.javacommunity.model.entity;

// Generated Nov 29, 2014 9:30:36 AM by Hibernate Tools 3.4.0.CR1
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import javax.persistence.CascadeType;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;

import static javax.persistence.GenerationType.IDENTITY;

import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.persistence.UniqueConstraint;
import org.hibernate.annotations.Fetch;
import org.hibernate.annotations.FetchMode;


/**
 * Question generated by hbm2java
 */
@Entity
@Table(name = "question", catalog = "db_javadanang",
       uniqueConstraints = @UniqueConstraint(columnNames = "questionName"))
public class Question implements java.io.Serializable {

    private Integer questionId;
    private User user;
    private String questionName;
    private String questionDetail;
    private Date createDate;
    private Date updateDate;
    private int viewCount;
    private boolean active;
    private List<UserQuestion> userQuestions = new ArrayList<UserQuestion>();
    private List<Answer> answers = new ArrayList<Answer>();
    private List<Tag> tags = new ArrayList<Tag>();

    public Question() {
    }

    public Question(User user, String questionName, String questionDetail,
            Date createDate, int viewCount, boolean active) {
        this.user = user;
        this.questionName = questionName;
        this.questionDetail = questionDetail;
        this.createDate = createDate;
        this.viewCount = viewCount;
        this.active = active;
    }

    public Question(User user, String questionName, String questionDetail,
            Date createDate, Date updateDate, int viewCount, boolean active,
            List<UserQuestion> userQuestions, List<Answer> answers,
            List<Tag> tags) {
        this.user = user;
        this.questionName = questionName;
        this.questionDetail = questionDetail;
        this.createDate = createDate;
        this.updateDate = updateDate;
        this.viewCount = viewCount;
        this.active = active;
        this.userQuestions = userQuestions;
        this.answers = answers;
        this.tags = tags;
    }

    @Id
    @GeneratedValue(strategy = IDENTITY)
    @Column(name = "questionId", unique = true, nullable = false)
    public Integer getQuestionId() {
        return this.questionId;
    }

    public void setQuestionId(Integer questionId) {
        this.questionId = questionId;
    }

    @ManyToOne(fetch = FetchType.EAGER)
    @Fetch (FetchMode.SELECT)
    @JoinColumn(name = "userId", nullable = false)
    public User getUser() {
        return this.user;
    }

    public void setUser(User user) {
        this.user = user;
    }

    @Column(name = "questionName", unique = true, nullable = false, length = 105)
    public String getQuestionName() {
        return this.questionName;
    }

    public void setQuestionName(String questionName) {
        this.questionName = questionName;
    }

    @Column(name = "questionDetail", nullable = false, length = 65535)
    public String getQuestionDetail() {
        return this.questionDetail;
    }

    public void setQuestionDetail(String questionDetail) {
        this.questionDetail = questionDetail;
    }

    @Temporal(TemporalType.DATE)
    @Column(name = "createDate", nullable = false, length = 10)
    public Date getCreateDate() {
        return this.createDate;
    }

    public void setCreateDate(Date createDate) {
        this.createDate = createDate;
    }

    @Temporal(TemporalType.DATE)
    @Column(name = "updateDate", length = 10)
    public Date getUpdateDate() {
        return this.updateDate;
    }

    public void setUpdateDate(Date updateDate) {
        this.updateDate = updateDate;
    }

    @Column(name = "viewCount", nullable = false)
    public int getViewCount() {
        return this.viewCount;
    }

    public void setViewCount(int viewCount) {
        this.viewCount = viewCount;
    }

    @Column(name = "active", nullable = false)
    public boolean isActive() {
        return this.active;
    }

    public void setActive(boolean active) {
        this.active = active;
    }

    @OneToMany(fetch = FetchType.LAZY, mappedBy = "question")
    public List<UserQuestion> getUserQuestions() {
        return this.userQuestions;
    }

    public void setUserQuestions(List<UserQuestion> userQuestions) {
        this.userQuestions = userQuestions;
    }

    @OneToMany(fetch = FetchType.EAGER, mappedBy = "question")
    @Fetch (FetchMode.SELECT)
    public List<Answer> getAnswers() {
        return this.answers;
    }

    public void setAnswers(List<Answer> answers) {
        this.answers = answers;
    }

    @ManyToMany(fetch = FetchType.EAGER, cascade = CascadeType.ALL)
    @JoinTable(name = "question_tag", catalog = "db_javadanang", joinColumns = {
        @JoinColumn(name = "questionId", nullable = false, updatable = false)},
            inverseJoinColumns = {
                @JoinColumn(name = "tagId",
                        nullable = false, updatable = false)})
    @Fetch (FetchMode.SELECT)
    public List<Tag> getTags() {
        return tags;
    }

    public void setTags(List<Tag> tags) {
        this.tags = tags;
    }

}
